home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue57 / Clinic / ButtonImpl.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-03-24  |  6.6 KB  |  261 lines

  1. unit ButtonImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, ActiveX, Classes, Controls, Graphics, Menus, Forms, StdCtrls,
  7.   ComServ, StdVCL, AXCtrls, ActiveX_TLB;
  8.  
  9. type
  10.   TMyButton = class(TButton)
  11.   private
  12.     FMyNewButtonProp: String;
  13.   published
  14.     property MyNewButtonProp: String read FMyNewButtonProp write FMyNewButtonProp;
  15.   end;
  16.  
  17.   TButtonX = class(TActiveXControl, IButtonX)
  18.   private
  19.     { Private declarations }
  20.     FDelphiControl: TMyButton;
  21.     FEvents: IButtonXEvents;
  22.     procedure ClickEvent(Sender: TObject);
  23.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  24.   protected
  25.     { Protected declarations }
  26.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  27.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  28.     procedure InitializeControl; override;
  29.     function DrawTextBiDiModeFlagsReadingOnly: Integer; safecall;
  30.     function Get_Cancel: WordBool; safecall;
  31.     function Get_Caption: WideString; safecall;
  32.     function Get_Cursor: Smallint; safecall;
  33.     function Get_Default: WordBool; safecall;
  34.     function Get_DoubleBuffered: WordBool; safecall;
  35.     function Get_DragCursor: Smallint; safecall;
  36.     function Get_DragMode: TxDragMode; safecall;
  37.     function Get_Enabled: WordBool; safecall;
  38.     function Get_Font: IFontDisp; safecall;
  39.     function Get_Visible: WordBool; safecall;
  40.     function Get_VisibleDockClientCount: Integer; safecall;
  41.     function IsRightToLeft: WordBool; safecall;
  42.     function UseRightToLeftReading: WordBool; safecall;
  43.     function UseRightToLeftScrollBar: WordBool; safecall;
  44.     procedure _Set_Font(const Value: IFontDisp); safecall;
  45.     procedure Click; safecall;
  46.     procedure InitiateAction; safecall;
  47.     procedure Set_Cancel(Value: WordBool); safecall;
  48.     procedure Set_Caption(const Value: WideString); safecall;
  49.     procedure Set_Cursor(Value: Smallint); safecall;
  50.     procedure Set_Default(Value: WordBool); safecall;
  51.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  52.     procedure Set_DragCursor(Value: Smallint); safecall;
  53.     procedure Set_DragMode(Value: TxDragMode); safecall;
  54.     procedure Set_Enabled(Value: WordBool); safecall;
  55.     procedure Set_Font(var Value: IFontDisp); safecall;
  56.     procedure Set_Visible(Value: WordBool); safecall;
  57.     function Get_MyNewButtonProp: WideString; safecall;
  58.     procedure Set_MyNewButtonProp(const Value: WideString); safecall;
  59.   end;
  60.  
  61. implementation
  62.  
  63. uses ComObj;
  64.  
  65. { TButtonX }
  66.  
  67. procedure TButtonX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  68. begin
  69.   {TODO: Define property pages here.  Property pages are defined by calling
  70.     DefinePropertyPage with the class id of the page.  For example,
  71.       DefinePropertyPage(Class_ButtonXPage); }
  72. end;
  73.  
  74. procedure TButtonX.EventSinkChanged(const EventSink: IUnknown);
  75. begin
  76.   FEvents := EventSink as IButtonXEvents;
  77. end;
  78.  
  79. procedure TButtonX.InitializeControl;
  80. begin
  81.   FDelphiControl := Control as TMyButton;
  82.   FDelphiControl.OnClick := ClickEvent;
  83.   FDelphiControl.OnKeyPress := KeyPressEvent;
  84. end;
  85.  
  86. function TButtonX.DrawTextBiDiModeFlagsReadingOnly: Integer;
  87. begin
  88.   Result := FDelphiControl.DrawTextBiDiModeFlagsReadingOnly;
  89. end;
  90.  
  91. function TButtonX.Get_Cancel: WordBool;
  92. begin
  93.   Result := FDelphiControl.Cancel;
  94. end;
  95.  
  96. function TButtonX.Get_Caption: WideString;
  97. begin
  98.   Result := WideString(FDelphiControl.Caption);
  99. end;
  100.  
  101. function TButtonX.Get_Cursor: Smallint;
  102. begin
  103.   Result := Smallint(FDelphiControl.Cursor);
  104. end;
  105.  
  106. function TButtonX.Get_Default: WordBool;
  107. begin
  108.   Result := FDelphiControl.Default;
  109. end;
  110.  
  111. function TButtonX.Get_DoubleBuffered: WordBool;
  112. begin
  113.   Result := FDelphiControl.DoubleBuffered;
  114. end;
  115.  
  116. function TButtonX.Get_DragCursor: Smallint;
  117. begin
  118.   Result := Smallint(FDelphiControl.DragCursor);
  119. end;
  120.  
  121. function TButtonX.Get_DragMode: TxDragMode;
  122. begin
  123.   Result := Ord(FDelphiControl.DragMode);
  124. end;
  125.  
  126. function TButtonX.Get_Enabled: WordBool;
  127. begin
  128.   Result := FDelphiControl.Enabled;
  129. end;
  130.  
  131. function TButtonX.Get_Font: IFontDisp;
  132. begin
  133.   GetOleFont(FDelphiControl.Font, Result);
  134. end;
  135.  
  136. function TButtonX.Get_Visible: WordBool;
  137. begin
  138.   Result := FDelphiControl.Visible;
  139. end;
  140.  
  141. function TButtonX.Get_VisibleDockClientCount: Integer;
  142. begin
  143.   Result := FDelphiControl.VisibleDockClientCount;
  144. end;
  145.  
  146. function TButtonX.IsRightToLeft: WordBool;
  147. begin
  148.   Result := FDelphiControl.IsRightToLeft;
  149. end;
  150.  
  151. function TButtonX.UseRightToLeftReading: WordBool;
  152. begin
  153.   Result := FDelphiControl.UseRightToLeftReading;
  154. end;
  155.  
  156. function TButtonX.UseRightToLeftScrollBar: WordBool;
  157. begin
  158.   Result := FDelphiControl.UseRightToLeftScrollBar;
  159. end;
  160.  
  161. procedure TButtonX._Set_Font(const Value: IFontDisp);
  162. begin
  163.   SetOleFont(FDelphiControl.Font, Value);
  164. end;
  165.  
  166. procedure TButtonX.Click;
  167. begin
  168.   FDelphiControl.Click;
  169. end;
  170.  
  171. procedure TButtonX.ClickEvent(Sender: TObject);
  172. begin
  173.   if FEvents <> nil then FEvents.OnClick;
  174. end;
  175.  
  176. procedure TButtonX.InitiateAction;
  177. begin
  178.   FDelphiControl.InitiateAction;
  179. end;
  180.  
  181. procedure TButtonX.KeyPressEvent(Sender: TObject; var Key: Char);
  182. var
  183.   TempKey: Smallint;
  184. begin
  185.   TempKey := Smallint(Key);
  186.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  187.   Key := Char(TempKey);
  188. end;
  189.  
  190. procedure TButtonX.Set_Cancel(Value: WordBool);
  191. begin
  192.   FDelphiControl.Cancel := Value;
  193. end;
  194.  
  195. procedure TButtonX.Set_Caption(const Value: WideString);
  196. begin
  197.   FDelphiControl.Caption := TCaption(Value);
  198. end;
  199.  
  200. procedure TButtonX.Set_Cursor(Value: Smallint);
  201. begin
  202.   FDelphiControl.Cursor := TCursor(Value);
  203. end;
  204.  
  205. procedure TButtonX.Set_Default(Value: WordBool);
  206. begin
  207.   FDelphiControl.Default := Value;
  208. end;
  209.  
  210. procedure TButtonX.Set_DoubleBuffered(Value: WordBool);
  211. begin
  212.   FDelphiControl.DoubleBuffered := Value;
  213. end;
  214.  
  215. procedure TButtonX.Set_DragCursor(Value: Smallint);
  216. begin
  217.   FDelphiControl.DragCursor := TCursor(Value);
  218. end;
  219.  
  220. procedure TButtonX.Set_DragMode(Value: TxDragMode);
  221. begin
  222.   FDelphiControl.DragMode := TDragMode(Value);
  223. end;
  224.  
  225. procedure TButtonX.Set_Enabled(Value: WordBool);
  226. begin
  227.   FDelphiControl.Enabled := Value;
  228. end;
  229.  
  230. procedure TButtonX.Set_Font(var Value: IFontDisp);
  231. begin
  232.   SetOleFont(FDelphiControl.Font, Value);
  233. end;
  234.  
  235. procedure TButtonX.Set_Visible(Value: WordBool);
  236. begin
  237.   FDelphiControl.Visible := Value;
  238. end;
  239.  
  240. function TButtonX.Get_MyNewButtonProp: WideString;
  241. begin
  242.   Result := FDelphiControl.MyNewButtonProp
  243. end;
  244.  
  245. procedure TButtonX.Set_MyNewButtonProp(const Value: WideString);
  246. begin
  247.   FDelphiControl.MyNewButtonProp := Value
  248. end;
  249.  
  250. initialization
  251.   TActiveXControlFactory.Create(
  252.     ComServer,
  253.     TButtonX,
  254.     TMyButton,
  255.     Class_ButtonX,
  256.     2,
  257.     '',
  258.     0,
  259.     tmApartment);
  260. end.
  261.